package com.triangle.cashier.adapter;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.triangle.cashier.R;

/**
 * 选择商品列表适配器
 * Created by  on 2018/6/30.
 */

public class PendingOrderAdapter extends BaseAdapter {
    public int count = 4;
    private LayoutInflater mInflater;//得到一个LayoutInfalter对象用来导入布局
    private Context context;
    private int selectIndex = 0;


    public PendingOrderAdapter(Context context) {
        this.context = context;

        this.mInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return count;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.pending_order_item, null);
            holder = new ViewHolder();
            holder.orderNumTextView = convertView.findViewById(R.id.order_num_TV);
            holder.orderTimeTextView = convertView.findViewById(R.id.order_time_TV);
            holder.orderNoteTextView = convertView.findViewById(R.id.order_note_TV);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (selectIndex == position) {
            convertView.setBackgroundColor(context.getColor(R.color.selected_goods_even_line_bg));
        } else {
            convertView.setBackgroundColor(context.getColor(R.color.selected_goods_odd_line_bg));
        }


        return convertView;
    }

    public void setSelectIndex(int index) {
        this.selectIndex = index;
        notifyDataSetChanged();
    }

    public interface OnChangeOnListener {
        void refresh();
    }

    /**
     * 存放控件
     */
    private final class ViewHolder {
        TextView orderNumTextView;
        TextView orderTimeTextView;
        TextView orderNoteTextView;


    }


}
